#!/bin/bash
if [ $# -lt 1 ];then
  echo "Usage: $0 [txtWordlist]"
  exit 1
fi

wordlst=$1
eachIndex=0

#while read iw
echo -e "wordlist==>mp4:"
if [[ -d ${wordlst%.*} ]]; then
  rm -rf ${wordlst%.*}
fi

mkdir ${wordlst%.*}
gsed -i "s/ /+/g" ${wordlst}
cat /dev/null > ${wordlst%.*}_list.txt 
for iw in $(cat ${wordlst})
do
  echo "${iw}"
  let eachIndex=eachIndex+1
  #if [ ! -f "curlwords/${iw}.txt" ];then
    python3 req-youdao.py ${iw} > "curlwords/${iw}.txt"
    gsed -i "s/(' //g;s/ ')//g;s/'//g;s/ $//g;s/^ //g;s/；/\n/3;/^$/d" "curlwords/${iw}.txt"
    sleep 1 #sleep for crawler
  #fi

  if [ -f curlwords/${iw}.txt ];then
    inTxt=$(cat "curlwords/${iw}.txt")
    #python3 pytext2jpg.py "${inTxt}" "curlwords/${iw}.jpg"
    echo "$inTxt" >> ${wordlst%.*}_list.txt
  fi
done
exit 0

